<template>
	<view class="invoiceInfo">
		<view class="invoiceInfo_item" v-for="item in invoiceInfoList.lists" :key="item.id" @tap="chooseInvoice(item)">
			<span class="fn-sz-28 fn-cl-999999 mar-right-20">开票抬头:</span>
			<span class="fn-sz-28 fn-cl-333333">{{ item.name }}</span>
		</view>
		<view class="fix_btn_box"><button class="yellow_btn" @tap="goLink('/pages/invoice/addInvoiceInfo')">添加开票信息</button></view>
	</view>
</template>

<script>
import com from '../../mixin/index.js';
export default {
	mixins: [com],
	data() {
		return {
			page: {
				page: 1,
				page_size: 4
			},
			invoiceInfoList: {
				lists: [],
				total: 1,
				total_page: 0
			},
			isEdit: true,
			params: {
				invoice_head_id: '',
				order_info: ''
			}
		};
	},
	onLoad(val) {
		if (val.lists) {
			this.$helper.toast('请选择开票信息');
			this.params.order_info = val.lists;
			this.isEdit = false;
		}
	},
	onShow() {
		this.page = {
			page: 1,
			page_size: 4
		};
		this.invoiceInfoList = {
			lists: [],
			total: 1,
			total_page: 0
		};
		this.getInvoiceHeadList();
	},
	methods: {
		getInvoiceHeadList() {
			this.getList('invoiceInfoList', 'getInvoiceHeadList', 'page', { ...this.page });
		},
		chooseInvoice(item) {
			if (this.isEdit) {
				uni.navigateTo({
					url: `/pages/invoice/addInvoiceInfo?info=${JSON.stringify(item)}`
				});
			} else {
				this.params.invoice_head_id = item.id;
				this.$api.applyInvoice(this.params).then(res => {
					console.log(res, '开票信息结果');
					this.$helper.toast(res.msg);
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack({
								delta: 2
							});
						}, 500);
					}
				});
			}
		}
	}
};
</script>

<style lang="scss">
.invoiceInfo {
	padding: 24rpx;
	min-height: 100vh;
	box-sizing: border-box;
	background-color: #f9f9f9;
	.invoiceInfo_item {
		margin-bottom: 20rpx;
		background: #ffffff;
		border-radius: 10rpx;
		padding: 26rpx 32rpx;
	}
	.fix_btn_box {
		position: fixed;
		bottom: 20rpx;
		width: 94%;
		margin: 0 auto;
	}
}
</style>
